<?php

namespace app\api\controller;

use app\common\controller\Api;
use EasyWeChat\Factory;

/**
 * 获取部门
 */
class Department extends Api
{

    //如果$noNeedLogin为空表示所有接口都需要登录才能请求
    //如果$noNeedRight为空表示所有接口都需要验证权限才能请求
    //如果接口已经设置无需登录,那也就无需鉴权了
    //
    // 无需登录的接口,*表示全部
    protected $noNeedLogin = ['*'];
    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = ['*'];

    protected $config = [
            'corp_id' => 'wxa8333bbf9962d0e0',//企业ID
            'secret'   => 'rnvyJF7szB2yCU6zttRdjSlq5M3AYcfQtYYadPGdFKg',//通讯录key
            // 指定 API 调用返回结果的类型：array(default)/collection/object/raw/自定义类名
            'response_type' => 'array',
            'log' => [
                'level' => 'debug',
                'file' => __DIR__.'/wechat.log',
            ],
        ];

    public function getDepartmentName($department)
    {
        $departmentList = $this->getDepartment();
        $departmentName = null;
        foreach ($department as $k=>$value)
        {
            $departmentName[] = $departmentList[$value]['name'];
        }
        return $departmentName;
    }


    /**
     *部门列表
     */
    public function getDepartment()
    {
        $department  = Factory::work($this->config);
        $departmentList  = $department->department->list();
        return array_column($departmentList['department'],NULL,'id');
    }

    public function test()
    {
        echo 1;exit;
    }

}
